extern "C" {
    pub type args;
    pub type cmds;
    pub type cmd;
    pub type cmdq_item;
    fn args_has(_: *mut args, _: u_char) -> i32;
    fn args_get(_: *mut args, _: u_char) -> *const i8;
    fn args_string(_: *mut args, _: u_int) -> *const i8;
    fn cmd_get_args(_: *mut cmd) -> *mut args;
    fn cmdq_error(_: *mut cmdq_item, _: *const i8, _: ...);
    fn key_bindings_get_table(_: *const i8, _: i32) -> *mut key_table;
    fn key_bindings_remove(_: *const i8, _: key_code);
    fn key_bindings_remove_table(_: *const i8);
    fn key_string_lookup_string(_: *const i8) -> key_code;
}
pub type __u_char = u8;
pub type __u_int = u32;
pub type __time_t = i64;
pub type __suseconds_t = i64;
pub type u_char = __u_char;
pub type u_int = __u_int;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct timeval {
    pub tv_sec: __time_t,
    pub tv_usec: __suseconds_t,
}
pub type key_code = u64;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_table {
    pub name: *const i8,
    pub activity_time: timeval,
    pub key_bindings: key_bindings,
    pub default_key_bindings: key_bindings,
    pub references: u_int,
    pub entry: C2RustUnnamed,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed {
    pub rbe_left: *mut key_table,
    pub rbe_right: *mut key_table,
    pub rbe_parent: *mut key_table,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_bindings {
    pub rbh_root: *mut key_binding,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct key_binding {
    pub key: key_code,
    pub cmdlist: *mut cmd_list,
    pub note: *const i8,
    pub flags: i32,
    pub entry: C2RustUnnamed_0,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub rbe_left: *mut key_binding,
    pub rbe_right: *mut key_binding,
    pub rbe_parent: *mut key_binding,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_list {
    pub references: i32,
    pub group: u_int,
    pub list: *mut cmds,
}
pub type args_parse_type = u32;
pub const ARGS_PARSE_COMMANDS: args_parse_type = 3;
pub const ARGS_PARSE_COMMANDS_OR_STRING: args_parse_type = 2;
pub const ARGS_PARSE_STRING: args_parse_type = 1;
pub const ARGS_PARSE_INVALID: args_parse_type = 0;
pub type args_parse_cb =
    Option<unsafe extern "C" fn(*mut args, u_int, *mut *mut i8) -> args_parse_type>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_parse {
    pub template: *const i8,
    pub lower: i32,
    pub upper: i32,
    pub cb: args_parse_cb,
}
pub type cmd_find_type = u32;
pub const CMD_FIND_SESSION: cmd_find_type = 2;
pub const CMD_FIND_WINDOW: cmd_find_type = 1;
pub const CMD_FIND_PANE: cmd_find_type = 0;
pub type cmd_retval = i32;
pub const CMD_RETURN_STOP: cmd_retval = 2;
pub const CMD_RETURN_WAIT: cmd_retval = 1;
pub const CMD_RETURN_NORMAL: cmd_retval = 0;
pub const CMD_RETURN_ERROR: cmd_retval = -1;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry_flag {
    pub flag: i8,
    pub type_0: cmd_find_type,
    pub flags: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry {
    pub name: *const i8,
    pub alias: *const i8,
    pub args: args_parse,
    pub usage: *const i8,
    pub source: cmd_entry_flag,
    pub target: cmd_entry_flag,
    pub flags: i32,
    pub exec: Option<unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval>,
}
#[no_mangle]
pub static mut cmd_unbind_key_entry: cmd_entry = {
    {
        let mut init = cmd_entry {
            name: b"unbind-key\0" as *const u8 as *const i8,
            alias: b"unbind\0" as *const u8 as *const i8,
            args: {
                let mut init = args_parse {
                    template: b"anqT:\0" as *const u8 as *const i8,
                    lower: 0 as i32,
                    upper: 1 as i32,
                    cb: None,
                };
                init
            },
            usage: b"[-anq] [-T key-table] key\0" as *const u8 as *const i8,
            source: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            target: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            flags: 0x4 as i32,
            exec: Some(
                cmd_unbind_key_exec as unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval,
            ),
        };
        init
    }
};
extern "C" fn cmd_unbind_key_exec(mut self_0: *mut cmd, mut item: *mut cmdq_item) -> cmd_retval {
    let mut args: *mut args = unsafe { cmd_get_args(self_0) };
    let mut key: key_code = 0;
    let mut tablename: *const i8 = std::ptr::null::<i8>();
    let mut keystr: *const i8 = unsafe { args_string(args, 0 as i32 as u_int) };
    let mut quiet: i32 = unsafe { args_has(args, 'q' as i32 as u_char) };
    if (unsafe { args_has(args, 'a' as i32 as u_char) }) != 0 {
        if !keystr.is_null() {
            if quiet == 0 {
                (unsafe { cmdq_error(item, b"key given with -a\0" as *const u8 as *const i8) });
            }
            return CMD_RETURN_ERROR;
        }
        tablename = unsafe { args_get(args, 'T' as i32 as u_char) };
        if tablename.is_null() {
            if (unsafe { args_has(args, 'n' as i32 as u_char) }) != 0 {
                tablename = b"root\0" as *const u8 as *const i8;
            } else {
                tablename = b"prefix\0" as *const u8 as *const i8;
            }
        }
        if (unsafe { key_bindings_get_table(tablename, 0 as i32) }).is_null() {
            if quiet == 0 {
                (unsafe {
                    cmdq_error(
                        item,
                        b"table %s doesn't exist\0" as *const u8 as *const i8,
                        tablename,
                    )
                });
            }
            return CMD_RETURN_ERROR;
        }
        (unsafe { key_bindings_remove_table(tablename) });
        return CMD_RETURN_NORMAL;
    }
    if keystr.is_null() {
        if quiet == 0 {
            (unsafe { cmdq_error(item, b"missing key\0" as *const u8 as *const i8) });
        }
        return CMD_RETURN_ERROR;
    }
    key = unsafe { key_string_lookup_string(keystr) };
    if key == 0xff000000000 as u64 || key == 0xfe000000000 as u64 {
        if quiet == 0 {
            (unsafe { cmdq_error(item, b"unknown key: %s\0" as *const u8 as *const i8, keystr) });
        }
        return CMD_RETURN_ERROR;
    }
    if (unsafe { args_has(args, 'T' as i32 as u_char) }) != 0 {
        tablename = unsafe { args_get(args, 'T' as i32 as u_char) };
        if (unsafe { key_bindings_get_table(tablename, 0 as i32) }).is_null() {
            if quiet == 0 {
                (unsafe {
                    cmdq_error(
                        item,
                        b"table %s doesn't exist\0" as *const u8 as *const i8,
                        tablename,
                    )
                });
            }
            return CMD_RETURN_ERROR;
        }
    } else if (unsafe { args_has(args, 'n' as i32 as u_char) }) != 0 {
        tablename = b"root\0" as *const u8 as *const i8;
    } else {
        tablename = b"prefix\0" as *const u8 as *const i8;
    }
    (unsafe { key_bindings_remove(tablename, key) });
    return CMD_RETURN_NORMAL;
}
